<?php
/*
* $Author ：PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2019 宿迁鑫潮信息技术有限公司，并保留所有权利。
*
* 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class index_controller extends common{
	function index_action(){
		
		if(!$this->config['did'] && $this->config['sy_gotocity']=='1' && !$_COOKIE['gotocity']){
			include(PLUS_PATH.'domain_cache.php');
			go_to_city($site_domain);
		}
		
		include PLUS_PATH.'/tplmoblie.cache.php';
		if($tplmoblie['wapdiy']==1||$_GET['type']==1){
			$this->get_moblie();
			
			$tplM	=	$this->MODEL('tpl');
			
			
			$nav = $tplM->getTplmobliepicList(array('type'=>'nav','orderby'=>'sort,asc'));
			$this->yunset(array('nav'=>$nav));
			
			$hd = $tplM->getTplmobliepicList(array('type'=>'hd'));
			$this->yunset('hd',$hd);
			
			$indexnav = $tplM->getTplmobliepicList(array('type'=>'indexnav','orderby'=>'id,asc'));
			foreach($indexnav as $k=>$v){
				$indexnav[$k]['indexnavurl']	=	$v['url'];
				if($k==0){
					$indexnav1	=	$v;
				}
				if($k==1){
					$indexnav2	=	$v;
				}
				if($k==2){
					$indexnav3	=	$v;
				}
			}
			$this->yunset('indexnav1',$indexnav1);
			$this->yunset('indexnav2',$indexnav2);
			$this->yunset('indexnav3',$indexnav3);
			
			$adlist = $tplM->getTplmobliepicList(array('type'=>'ad'));
			$this->yunset('adlist',$adlist);
			
			if($tplmoblie['rewardjobnum']<1){
				$tplmoblie['rewardjobnum']	=	5;
			}
			if($tplmoblie['hotjobnum']<1){
				$tplmoblie['hotjobnum']		=	8;
			}
			if($tplmoblie['newjobnum']<1){
				$tplmoblie['newjobnum']		=	5;
			}
			if($tplmoblie['hotcomnum']<1){
				$tplmoblie['hotcomnum']		=	5;
			}
			if($tplmoblie['articlenum']<1){
				$tplmoblie['articlenum']	=	5;
			}
			if($tplmoblie['resumenum']<1){
				$tplmoblie['resumenum']		=	5;
			}
			if($tplmoblie['urgentjobnum']<1){
				$tplmoblie['urgentjobnum']	=	5;
			}
			if($tplmoblie['recjobnum']<1){
				$tplmoblie['recjobnum']		=	5;
			}
			if($tplmoblie['zphnum']<1){
				$tplmoblie['zphnum']		=	5;
			}
			$this->yunset('tplmoblie',$tplmoblie);
			
			//显示顺序
			if( $tplmoblie['sort']){
				$sort=explode(',', $tplmoblie['sort']);
			}else{
				$sort='hearder,hd,search,nav,indexnav,notice,reglogin,ad,rewardjob,hotjob,newjob,hotcom,recjob,urgentjob,resume,article,zph,jobclass';
				$sort=explode(',', $sort);
			}
			$this->yunset('sort',$sort);
			//搜索类型
			$searchurl	=	array(
				array('id'=>1,'c'=>'job','name'=>'找工作'),
				array('id'=>2,'c'=>'resume','name'=>'找人才'),
				array('id'=>3,'c'=>'company','name'=>'找企业'),
				array('id'=>4,'c'=>'part','name'=>'找兼职'),
				array('id'=>5,'c'=>'tiny','name'=>'普工专区'),
				array('id'=>6,'c'=>'once','name'=>'店铺招聘'),
				array('id'=>7,'c'=>'ltjob','name'=>'猎头职位'),
				array('id'=>8,'c'=>'ltjob','a'=>'service','name'=>'委托求职'),
				array('id'=>9,'c'=>'train','name'=>'培训课程'),
				array('id'=>10,'c'=>'train','a'=>'agency','name'=>'培训机构'),
				array('id'=>11,'c'=>'train','a'=>'teacher','name'=>'培训讲师'),
				array('id'=>12,'c'=>'ask','a'=>'list','name'=>'互动问答')
			);
			$this->yunset('searchurl',$searchurl);
			$this->yunset($this->MODEL('cache')->GetCache(array('job')));
			if($this->config["did"]){
				$this->seo("index",$this->config['sy_webtitle'],$this->config['sy_webkeyword'],$this->config['sy_webmeta']);
			}else{
				$this->seo('index');
			}
			$this->yunset('indexnav',1);
			$this->yuntpl(array('wap/wap_diy'));
		}else{
			
			include PLUS_PATH.'menu.cache.php';
			$navlist			=	$menu_name[26];
			foreach($navlist as $k=>$v){

				$navlist[$k]['pic_n']	=	checkpic($v['pic']);
				
				if($v['type']=='2'){
					$navlist[$k]['url_n']	=	$v['url'];
				}else{
					if(strpos($v['url'],'&')!==false && strpos($v['url'],'=')!==false){
						$url = explode('&',$v['url']);
						foreach($url as $key=>$value){

							$urls = explode('=',$value);
							$sonUrl[$urls[0]] = $urls[1];
						}
						$navlist[$k]['url_n']	=	Url('wap',$sonUrl);
						unset($sonUrl);
					}else{
					
						$navlist[$k]['url_n']	=	Url('wap',array('c'=>$v['url']));
					}
					
					
				}
			}
			
			$this->get_moblie();
			if($this->config["did"]){
				$this->seo("index",$this->config['sy_webtitle'],$this->config['sy_webkeyword'],$this->config['sy_webmeta']);
			}else{
				$this->seo('index');
			}
			$this->yunset('navlist',$navlist);
			$this->yunset('indexnav',1);
			$this->yuntpl(array('wap/index'));
		}
	}

	function loginout_action(){
		$this->cookie->unset_cookie();
		$this->wapheader('');
	}
	// 关于我们
	function about_action()
	{
	    $descM    =   $this->MODEL('description');
	    $content  =   $descM -> getDes(array('name'=>'关于我们'),array('field'=>'content'));
	    $this->yunset('content',$content);
	    if ($_GET['fr'] == 'wxapp'){
	        $this->yunset('wxapp',1);
	    }
	    $this->yunset('headertitle','关于我们');
	    $this->yunset('title','关于我们');
	    $this->yuntpl(array('wap/about'));
	}
	// 联系我们
	function contact_action()
	{
	    $descM    =   $this->MODEL('description');
	    $content  =   $descM -> getDes(array('name'=>'联系我们'),array('field'=>'content'));
	    $this->yunset('content',$content);
	    if ($_GET['fr'] == 'wxapp'){
	        $this->yunset('wxapp',1);
	    }
	    $this->yunset('headertitle','联系我们');
	    $this->yunset('title','联系我们');
	    $this->yuntpl(array('wap/about'));
	}
	//下载app
	function appDown_action()
	{
	    $this->yunset('headertitle','下载APP');
	    $this->yuntpl(array('wap/appdown'));
	}
	// 隐私政策
	function private_action()
	{
	    $descM    =   $this->MODEL('description');
	    $content  =   $descM -> getDes(array('name'=>'隐私政策'),array('field'=>'content'));
	    $this->yunset('content',$content);
	    if ($_GET['fr'] == 'wxapp'){
	        $this->yunset('wxapp',1);
	    }
	    $this->yunset('headertitle','隐私政策');
	    $this->yunset('title','隐私政策');
	    $this->yuntpl(array('wap/about'));
	}
	// 用户协议
	function protocol_action()
	{
	    $descM    =   $this->MODEL('description');
	    $content  =   $descM -> getDes(array('name'=>'注册协议'),array('field'=>'content'));
	    $this->yunset('content',$content);
	    if ($_GET['fr'] == 'wxapp'){
	        $this->yunset('wxapp',1);
	    }
	    $this->yunset('headertitle','用户协议');
	    $this->yunset('title','用户协议');
	    $this->yuntpl(array('wap/about'));
	}
	// /提示相关信息
	function applytype_action(){
		$memberM		=	$this -> MODEL('userinfo');
		$uid			=	$this->uid;
		$res			=	$memberM->getapplytype($uid);
		echo json_encode(array('msg'=>$res['msg'],'url'=>$res['url'],'wxopenid'=>$res['wxopenid'],'wxid'=>$res['wxid'],'errcode'=>$res['errcode']));die;
	}
	//已拒绝重新弹出
	function applystype_action(){
		
		$memberM			=			$this -> MODEL('userinfo');
		
		$uid				=			$this->uid;
		
		$res				=			$memberM->getapplyyjjtype($uid);
		echo json_encode(array('msg'=>$res['msg'],'url'=>$res['url'],'errcode'=>$res['errcode']));die;
	}
	//切换身份
	function changeusertype_action(){
		$memberM	=	  $this -> MODEL('userinfo');
		$uid      	=     $this->uid;
		if($uid==""){
			$res['url']			=	Url('wap',array('c'=>'login'));
			$res['msg']			=	'请先登录';
			echo json_encode(array('msg'=>$res['msg'],'url'=>$res['url']));die;
		}
		$where['uid']			=		$uid;
		$rows					=		$memberM->getInfo($where,array('field'=>'`usertype`,`pid`'));
	
		if($rows){
			$userwhere['uid']				=		$uid;
			$userwhere['pres_usertype']		=		$rows['usertype'];
			$userwhere['status']			=		0;	
			
			$cahnge							=		$memberM->getUserChangeInfo($userwhere);
		
			if($cahnge){
				$usertype	=	array('1'=>'个人会员','2'=>'企业会员','3'=>'猎头会员','4'=>'培训会员');
				$res['msg']			=		'当前已申请'.$usertype[$cahnge['apply_usertype']].'转换,无法申请其他会员';
				$res['url']			=		$_SERVER['HTTP_REFERER'];
				echo json_encode(array('msg'=>$res['msg'],'url'=>$res['url']));die;
			}
			if($rows['pid']>0){
				$res['msg']			=		'子账号不支持转换';
				$res['url']			=		$_SERVER['HTTP_REFERER'];
				echo json_encode(array('msg'=>$res['msg'],'url'=>$res['url']));die;
			}
			if($_POST['applyusertype']==""){
				$res['msg']			=		'请选择转换会员类型';
				$res['url']			=		$_SERVER['HTTP_REFERER'];
				echo json_encode(array('msg'=>$res['msg'],'url'=>$res['url']));die;
			}elseif($rows['usertype']==$_POST['applyusertype']){
			
				$res['msg']			=		'选择转换会员类型与当前会员类型一致，无须切换';
				$res['url']			=		$_SERVER['HTTP_REFERER'];
				echo json_encode(array('msg'=>$res['msg'],'url'=>$res['url']));die;
			}
			$addData				=		array(
				'uid'				=>		$uid,
				'name'				=>		$this->username,
				'did'				=>		$this->userdid,
				'apply_usertype'	=>		$_POST['applyusertype'],
				'pres_usertype'		=>		$this->usertype,
				'applybody'			=>		$_POST['applybody'],
				'apply_time'		=>		time(),
				'lastupdate'		=>		time(),
				'type'				=>		1,
				'state'				=>		0,
			);
			$return					=		$memberM->addUserChange($addData);
			if($return){
				$res['msg']			=		'申请成功，等待审核';
				$res['url']			=		$_SERVER['HTTP_REFERER'];
				echo json_encode(array('msg'=>$res['msg'],'url'=>$res['url']));die;
			}else{
				$res['msg']			=		'申请转换会员类型失败';
				$res['url']			=		$_SERVER['HTTP_REFERER'];
				echo json_encode(array('msg'=>$res['msg'],'url'=>$res['url']));die;
			}
		}else{
			$res['msg']				=		'数据不存在';
			$res['url']				=		$_SERVER['HTTP_REFERER'];
			echo json_encode(array('msg'=>$res['msg'],'url'=>$res['url']));die;
		}
		
	}
}
?>